package com.msc.cili.service.guestmessage.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msc.cili.common.utils.BdUtil;
import com.msc.cili.repository.dao.guestmessage.CommentMapper;
import com.msc.cili.repository.dao.guestmessage.to.PageCommentTo;
import com.msc.cili.repository.entity.guestmessage.Comment;
import com.msc.cili.service.guestmessage.CommentService;

import com.msc.cili.service.guestmessage.bo.PageCommentBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author coder-msc
 * @date 2021-04-08
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Autowired
    CommentMapper commentMapper;


    /**
     * 通过博客id和父评论id查找所有子评论 并按照时间倒序排序
     *
     * @param blogId
     * @param parentCommentId
     * @return
     */
    @Override
    public List<PageCommentBo> getPageCommentListByDesc(Long blogId, Long parentCommentId) {
        List<PageCommentTo> pageCommentListByPageAndParentCommentIdByDesc = commentMapper.getPageCommentListByPageAndParentCommentIdByDesc(blogId, parentCommentId);
        List<PageCommentBo> pageCommentBos = BdUtil.bo2do4List(pageCommentListByPageAndParentCommentIdByDesc, PageCommentBo.class);
        return pageCommentBos;
    }

    /**
     * 通过博客id和父评论id查找所有子评论
     *
     * @param blogId
     * @param parentCommentId
     * @return
     */
    @Override
    public List<PageCommentBo> getPageCommentList(Long blogId, Long parentCommentId) {
        List<PageCommentTo> pageCommentListByPageAndParentCommentId = commentMapper.getPageCommentListByPageAndParentCommentId(blogId, parentCommentId);
        List<PageCommentBo> pageCommentBos = BdUtil.bo2do4List(pageCommentListByPageAndParentCommentId, PageCommentBo.class);
        return pageCommentBos;
    }


}
